#include <libpaysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int GetOpCode(char* op)
{
    if(!op || !*op) return -1;
    if(!strcmp(op,"mt")) return 0;
    if(!strcmp(op,"es")) return 1;
    if(!strcmp(op,"be")) return 2;
    if(!strcmp(op,"br")) return 3;
    if(!strcmp(op,"bb")) return 4;
    if(!strcmp(op,"me")) return 5;
    if(!strcmp(op,"nw")) return 6;
    if(!strcmp(op,"so")) return 7;
    if(!strcmp(op,"ze")) return 8;
    if(!strcmp(op,"nt")) return 9;
    return -1;
}


int main(int argc,char** argv)
{
    if(argc<5)
    {
	printf("USAGE: sendreq [USER]:[PASS]@[HOST]/DBASE OPERATOR PHONE AMOUNT [p]\n");
	return 0;
    }

    int method=REQ_PHONECHECK;

    if(argc>5 && *argv[5]=='p')
	method=REQ_PAYMENT;
	
    int opcode=GetOpCode(argv[2]);
    if(opcode<0)
    {
	printf("unknown operator\n");
	return 0;
    }
	
    CMySQLConnection sql;
    if(!sql.Connect(argv[1]))
	printf("%s\n",sql.GetLastError());
    else
    {
	CPayRequest req(sql);
	int n = req.SendRequest(method,opcode,argv[3],atof(argv[4]));
	if (n < 0)
	    printf("%s\n",sql.GetLastError());
	else printf("success. reqid=%i\n",n);
    }
    return 0;
}
